home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------
-
- amiga.c
-
- Amiga-specific routines for use with Info-ZIP's UnZip 5.1 and later.
-
- ---------------------------------------------------------------------------*/
-
-
- #include "unzip.h"
-
- #ifndef S_ISCRIPT /* not having one implies you have none */
- # define S_IARCHIVE 0020 /* not modified since this bit was last set */
- # define S_IREAD 0010 /* can be opened for reading */
- # define S_IWRITE 0004 /* can be opened for writing */
- # define S_IDELETE 0001 /* can be deleted */
- #endif
- #ifndef S_IRWD
- # define S_IRWD 0015 /* useful combo of Amiga privileges */
- #endif
- #ifndef S_IHIDDEN
- # define S_IHIDDEN 0200 /* hidden supported in future AmigaDOS 3.x */
- #endif
-
-
-
- /**********************/
- /* Function mapattr() */
- /**********************/
-
- int mapattr() /* Amiga version */
- {
- ulg tmp = crec.external_file_attributes;
-
-
- /* Amiga attributes = hsparwed = hidden, script, pure, archive,
- * read, write, execute, delete */
-
- switch (pInfo->hostnum) {
- case AMIGA_:
- /* turn off archive bit for restored Amiga files */
- pInfo->file_attr = (unsigned)((tmp>>16) & (~S_IARCHIVE));
- break;
-
- case UNIX_: /* preserve read, write, execute: use logical-OR of */
- case VMS_: /* user, group, and other; if writable, set delete bit */
- tmp >>= 16;
- tmp = (( tmp>>6 | tmp>>3 | tmp) & 07) << 1;
- pInfo->file_attr = (unsigned)(tmp&S_IWRITE? tmp|S_IDELETE : tmp);
- break;
-
- /* all other platforms: assume read-only bit in DOS half of attribute
- * word is set correctly ==> will become READ or READ+WRITE+DELETE */
- case FS_FAT_:
- case FS_HPFS_: /* can add S_IHIDDEN check to MSDOS/OS2/NT eventually */
- case FS_NTFS_:
- case MAC_:
- case ATARI_:
- case TOPS20_:
- default:
- pInfo->file_attr = (unsigned)(tmp&1? S_IREAD : S_IRWD);
- break;
-
- } /* end switch (host-OS-created-by) */
-
- pInfo->file_attr &= 0xff; /* mask off all but lower eight bits */
- return 0;
-
- } /* end function mapattr() */
-
-
-
-
-
- /**************************************/
- /* Function set_file_time_and_close() */
- /**************************************/
-
- void set_file_time_and_close()
- {
- static short yday[]={0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
- long m_time;
- int yr, mo, dy, hh, mm, ss, leap, days=0;
- struct utimbuf {
- time_t actime; /* new access time */
- time_t modtime; /* new modification time */
- } tp;
- # define YRBASE 1978 /* in AmigaDos, counting begins 01-Jan-1978 */
- struct DateStamp myadate;
-
-
- if (cflag) /* can't set time on stdout */
- return;
-
- /* close the file *before* setting its time under AmigaDos */
- close(outfd);
-
- /* dissect MSDOS-format date and time */
- yr = ((lrec.last_mod_file_date >> 9) & 0x7f) + (1980 - YRBASE);
- mo = ((lrec.last_mod_file_date >> 5) & 0x0f) - 1;
- dy = (lrec.last_mod_file_date & 0x1f) - 1;
- hh = (lrec.last_mod_file_time >> 11) & 0x1f;
- mm = (lrec.last_mod_file_time >> 5) & 0x3f;
- ss = (lrec.last_mod_file_time & 0x1f) * 2;
-
- /* leap = # of leap years from BASE up to but not including current year */
- leap = ((yr + YRBASE - 1) / 4); /* leap year base factor */
-
- /* How many days from BASE to this year? (& add expired days this year) */
- days = (yr * 365) + (leap - 492) + yday[mo];
-
- /* if year is a leap year and month is after February, add another day */
- if ((mo > 1) && ((yr+YRBASE)%4 == 0) && ((yr+YRBASE) != 2100))
- ++days; /* OK through 2199 */
-
- myadate.ds_Days = days + dy - 2; /* off by one? */
- myadate.ds_Minute = hh*60 + mm;
- myadate.ds_Tick = ss*TICKS_PER_SECOND;
-
- if (!FileDate(filename, &myadate))
- fprintf(stderr, "warning: can't set the time for %s\n", filename);
-
- /* set file perms after closing (not done at creation)--see mapattr() */
- chmod(filename, pInfo->file_attr);
-
- } /* end function set_file_time_and_close() */
-